<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/27
 * Time: 10:19
 */

namespace Wechat\Controller;


class PaymentController extends CommonController {

    /**
     * 留言
     */
    public function index() {
        $customerId = $this->customer["customer_id"];

        $paymentMap["customer_id"] = $customerId;
        $paymentMap["day"] = date("Y-m-d");
        $payment = D("Payment")->queryByMap($paymentMap);
        

        $this->assign("customerId", $customerId);
        $this->assign("info", $payment);
        $this->display("index");

    }

    public function createPayment() {

        $data["code"] = 200;

        $paymentData["create_time"] = getCurrentDate();
        $paymentData["status"] = -1;
        $paymentData["customer_id"] = $this->customer["customer_id"];
        $paymentData["name"] = I("post.name");
        $paymentData["amount"] = I("post.amount");
//        $paymentData["number"] = I("post.number");
//        $paymentData["sales_id"] = I("post.salesId");
        $paymentData["payment_content"] = I("post.paymentContent");

        $payId = D('Pay')->add(array(
            'out_trade_no' => time() . rand(0, 999),
            'money' => $paymentData["amount"],
            'status' => 0,
            'type' => 0,
            'callback' => "",
            'create_time' => getCurrentDate(),
            'update_time' => getCurrentDate(),
            'pay_source' => 1
        ));

        $paymentData["pay_id"] = $payId;

        $paymentId = D("Payment")->add($paymentData);

        $data["payment_id"] = $paymentId;

        echo json_encode($data);

    }

}